package cn.lotusnut.dynamicscheduled.task;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.ParseException;
import technology.tabula.CommandLineApp;

import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

/**
 * @Author JiangMing Zhou
 * @Date 2023/4/23 11:01
 * @Version 1.8
 */
public class DemoTask {

    public void task1() {
        System.out.println("task1");
    }

    public void task2() {
        System.out.println("task2");
    }

    public static void main(String[] args) throws ParseException {
        //-f导出格式,默认CSV  (一定要大写)
        //-p 指导出哪页,all是所有
        //path　D:\\1xx.pdf
        //-l 强制使用点阵模式提取PDF　（关键在于这儿）
        /*String[] argsa = new String[]{"-f=JSON", "-p=all", "E:\\BaiduNetdiskDownload\\00015核心单词.pdf","-t"};
        CommandLineParser parser = new DefaultParser();
        CommandLine cmd = parser.parse(CommandLineApp.buildOptions(), argsa);
        StringBuilder stringBuilder = new StringBuilder();
        new CommandLineApp(stringBuilder, cmd).extractTables(cmd);
        JSONArray data = JSONArray.parse(stringBuilder.toString());
        System.out.println(data);
        Map<String,String> wordMap = new LinkedHashMap<>();
        Set<String> errorWord = new LinkedHashSet<>();
        int dataIndex = 0;
        for (int i = 0; i < data.size(); i++) {
            int rowIndexStart = 0;
            if (i == 0 || i == 2){
                rowIndexStart = 1;
            }
            JSONObject pageData = data.getJSONObject(i);
            JSONArray tabletData = pageData.getJSONArray("data");
            for (int j = rowIndexStart; j < tabletData.size(); j++) {
                String wordCell = tabletData.getJSONArray(j).getJSONObject(dataIndex).getString("text");
                try {
                    String word = wordCell.substring(wordCell.indexOf(".")+1,wordCell.indexOf("[")).trim();
                    wordMap.put(word,wordCell.substring(0,wordCell.indexOf(".")));
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
        System.out.println(wordMap.keySet());
        System.err.println(errorWord);*/
    }
}
